package com.xnx.bincker.leader.controller.admin.system;

import com.xnx.bincker.leader.core.annotation.Authority;
import com.xnx.bincker.leader.core.annotation.Menu;
import com.xnx.bincker.leader.domain.Role;
import com.xnx.bincker.leader.domain.User;
import com.xnx.bincker.leader.utils.RestLinkUtils;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

import static com.xnx.bincker.leader.utils.RestLinkUtils.links;

@RestController("adminSystemIndexController")
@RequestMapping("/admin/system")
public class IndexController {
    private final RestLinkUtils linkUtils;

    public IndexController(RestLinkUtils linkUtils) {
        this.linkUtils = linkUtils;
    }

    @GetMapping
    @Menu(id="f40058f6-0c98-4d45-9d1b-47782104251d", name = "系统:首页")
    @Authority(id="a701369f-07d3-4fa8-8057-f4b1969ead49", remark = "系统首页")
    public Map<String, List<RestLinkUtils.Link>> index() throws NoSuchMethodException {
        return links(
                linkUtils.getLink("userGrid", UserController.class.getMethod("list", User.class, int.class, int.class, Sort.class)),
                linkUtils.getLink("roleGrid", RoleController.class.getMethod("list", Role.class, int.class, int.class))
        );
    }
}
